#include "fun.h"

u8 bdata com;
sbit BUZZER = com^6;
sbit RELAY = com^4;
u8 key_value = 0;

void buzzer(u8 cmd)
{
	BUZZER = cmd;
	P0 = com;
	P2 = 0xa0;
	_nop_();
	P2 = 0x00;
}

void relay(u8 cmd)
{
	RELAY = cmd;
	P0 = com;
	P2 = 0xa0;
	_nop_();
	P2 = 0x00;
}

void led(u8 ucode)
{
	P0 = ~ucode;
	P2 = 0x80;
	_nop_();
	P2 = 0x00;
}

void key_scan(void)
{
	static u8 key_up = 1;
	if(key_up&&(P33==0||P32==0||P31==0||P30==0))
	{
		key_up = 0;
		if(!P33)
			key_value = 4;
		else if(!P32)
			key_value = 5;
		else if(!P31)
			key_value = 6;
		else if(!P30)
			key_value = 7;
	}
	else if(P33&&P32&&P31&&P30)
		key_up = 1;
}

void smg_disp(u8 num,u8 position)
{
	P0 = position;
	P2 = 0xc0;
	_nop_();
	P2 = 0x00;

	P0 = ~num;
	P2 = 0xe0;
	_nop_();
	P2 = 0x00;
}